package com.tools.sqlmaker.make.impl;

import cn.hutool.core.text.CharSequenceUtil;
import com.tools.sqlmaker.entry.OrgInfo;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: zhoubin
 * @date: 2023/9/7
 */
public class MqMgrConfMaker extends GatewayBaseMaker {

    public MqMgrConfMaker(OrgInfo info) {
        super(info);
    }

    @Override
    public List<Map<String, Object>> getParamList() {
        OrgInfo info = getOrgInfo();

        String mqQmName = choseMqQmName();

        List<Map<String, Object>> paramList = new ArrayList<>();
        for (int i = 0; i < info.getMgrNum(); i++) {
            Map<String, Object> map = makeDefaultMap();
            char qmNum = (char) (65 + i);
            String qmCode = getQmCodePre() + qmNum;

            map.put("qm_code", qmCode);
            map.put("qm_name", getQmCodePre() + "队列管理器" + qmNum);
            map.put("qm_type", choseMqName());
            map.put("unit_code", getUnitCode());
            map.put("mq_qm_name", CharSequenceUtil.isNotBlank(mqQmName) ? mqQmName + qmNum : null);

            paramList.add(map);
        }

        return paramList;
    }

    @Override
    protected Map<String, Object> makeDefaultMap() {
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("id", idMake());
        map.put("qm_code", null);
        map.put("qm_name", null);
        map.put("qm_type", null);
        map.put("ref_type", "R");
        map.put("dc_code", null);
        map.put("unit_code", null);
        map.put("host", "0");
        map.put("port", "0");
        map.put("user_name", null);
        map.put("password", null);
        map.put("conn_chl_name", "0");
        map.put("mq_qm_name", null);
        map.put("ext_param", null);
        map.put("status", "0");
        return map;
    }

    @Override
    protected String getTableName() {
        return "t_ccgw_q_mgr_conf";
    }

    public String choseMqQmName() {
        OrgInfo info = getOrgInfo();

        String mqQmName = null;

        switch (info.getQType()) {
            case "IBMMQ":
                mqQmName = "QMUCAE";
                break;
            case "TLQ":
                mqQmName = "CISD" + info.getOrgBic();
                break;
            default:
        }

        return mqQmName;
    }

    public String choseMqName() {
        OrgInfo info = getOrgInfo();

        String mqName = null;

        switch (info.getQType()) {
            case "IBMMQ":
                mqName = "mq";
                break;
            case "TLQ":
                mqName = "tlq";
                break;
            case "ROCKETMQ":
                mqName = "rmq";
                break;
            case "RABBITMQ":
                mqName = "rabbit";
                break;
            default:
        }

        return mqName;
    }
}
